import os
import random
import time
from multiprocessing import Pool


def work(msg):
    t_start=time.time()
    print(f'{msg}开始执行，进程号为：{os.getpid()}')
    time.sleep(random.random()*2)
    t_end=time.time()
    print(msg,f"执行完毕，耗时:{t_end-t_start}")


if __name__ == '__main__':
    po = Pool(3)
    for i in range(10):
        po.apply_async(work, (i,))
    print('-------start------')
    po.close()
    po.join()
    print("-------end--------")